import java.util.Comparator;
import java.util.PriorityQueue;
//https://leetcode.cn/problems/smallest-k-lcci/description/
class Solution {
    public int[] smallestK(int[] arr, int k) {
        int[] ret = new int[k];
        if(k == 0) return ret;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((o1,o2)-> o2-o1);
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }
        for (int j = k; j < arr.length; j++) {
            if (arr[j] < priorityQueue.peek()) {
                priorityQueue.poll();
                priorityQueue.offer(arr[j]);
            }
        }
        for (int i = 0; i < k; i++) {
            ret[i] = priorityQueue.poll();
        }
        return ret;
    }
}